<html>
<head><meta charset="utf-8"><title>Types showing as ! · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html">Types showing as !</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179742965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179742965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eryn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179742965">(Nov 03 2019 at 11:06)</a>:</h4>
<p>Hey sorry if this is a known issue but I ran into a problem where items imported from a crate have methods that show as returning <code>!</code> or <code>{unknown}</code>. The code works fine when compiled but rust-analyzer just shows the types incorrectly in the IDE. This is the crate specifically <a href="https://docs.rs/scrap/0.5.0/scrap/" target="_blank" title="https://docs.rs/scrap/0.5.0/scrap/">https://docs.rs/scrap/0.5.0/scrap/</a>. Just wondering where the problem is and if it's with my setup is there any way I can fix this?</p>



<a name="179744998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179744998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179744998">(Nov 03 2019 at 12:15)</a>:</h4>
<p>rust-analyzer does its own name resolution and type inference, which isn't yet completely correct in some cases. That said, <code>!</code> and <code>{unknown}</code> are very different cases; <code>{unknown}</code> can easily happen when we can't resolve something e.g. because of some macro that we can't handle yet, whereas I would expect <code>!</code> to wrongly show up only in some edge cases with e.g. <code>match</code> or <code>if</code> within a function body, not as the return type of a method.</p>
<p>We would have to look at the specific cases for more detail; it's possible or even likely that they're related to a known limitation, but it's hard to tell in this generality <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="179745323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179745323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eryn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179745323">(Nov 03 2019 at 12:24)</a>:</h4>
<p>Makes sense</p>
<p>The return from this function here <a href="https://docs.rs/scrap/0.5.0/scrap/struct.Capturer.html#method.frame" target="_blank" title="https://docs.rs/scrap/0.5.0/scrap/struct.Capturer.html#method.frame">https://docs.rs/scrap/0.5.0/scrap/struct.Capturer.html#method.frame</a> is being displayed as <code>Result&lt;!, {unknown}&gt;</code></p>



<a name="179746292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179746292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179746292">(Nov 03 2019 at 12:57)</a>:</h4>
<p>As far as I can see, we can't even resolve <code>scrap::Capturer</code>, presumably because of all the conditional compilation going on there, so that type probably comes from how it's being used, and if you e.g. do a match on the <code>Result</code> where you <code>return</code> on the <code>Err</code> branch, that'll lead to inferring <code>!</code> for the <code>Ok</code> type</p>



<a name="179746403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179746403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179746403">(Nov 03 2019 at 13:00)</a>:</h4>
<p>ah, it uses <code>build.rs</code> to set some cfgs... I doubt we can handle that at the moment, so none of them is set, hence we don't resolve anything in there (since it doesn't have a fallback implementation)</p>



<a name="179746419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179746419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179746419">(Nov 03 2019 at 13:01)</a>:</h4>
<p>we used to kind of handle this better before we implemented the support for <code>cfg</code> we currently have...</p>



<a name="179759558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179759558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eryn <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179759558">(Nov 03 2019 at 19:20)</a>:</h4>
<p>Is there a way I can help it along and sort of assert what type something is just within the context of rust-analyzer? Even doing <code>let capturer: Capturer = Capturer::new(display).unwrap();</code> makes it say <code>{unknown}</code>, shouldn't it be able to know that it's a <code>Capturer</code> since I set the type explicitly in the assignment?</p>



<a name="179759576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179759576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Mcnab <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179759576">(Nov 03 2019 at 19:21)</a>:</h4>
<p>That suggests that it can't resolve capturer, which is pretty much the same issue.</p>



<a name="179759917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179759917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Mcnab <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179759917">(Nov 03 2019 at 19:31)</a>:</h4>
<p>So the only way around it that I can see is to define your own Capturer with the minimum interface that you need, perhaps as a new type struct around the real Capturer</p>



<a name="179761386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Types%20showing%20as%20%21/near/179761386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Types.20showing.20as.20!.html#179761386">(Nov 03 2019 at 20:07)</a>:</h4>
<p>In this case, we don't know <code>Capturer</code> at all because we never even include any of the modules that define it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>